import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:get_storage/get_storage.dart';
class TestPage extends StatelessWidget {
  CountController _countController = Get.put(CountController());
  // var pickedImage = null.obs;
  var storage = GetStorage();
  Rx<XFile?> pickedImage = Rx(null);
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ElevatedButton(
          onPressed: () async {
            _countController.increment();
            final picker = ImagePicker();
            var image = await picker.pickImage(source: ImageSource.gallery);
            if (image != null) {
              pickedImage.value = image;
            }
            Get.snackbar(
              "title",
              "message",
              colorText: Colors.blue,
              icon: Icon(Icons.cloud_done),
              duration: Duration(seconds: 2),
              borderRadius: 20,
              mainButton: TextButton(
                onPressed: () => {print(5555)},
                child: Text("click"),
              ),
              snackStyle: SnackStyle.FLOATING,
            );
          },
          child: Text("点击选择图片"),
        ),

        Obx(() {
          print(storage.read("userName"));
          if (pickedImage.value == null) {
            return Text("还没选图片");
          } else {
            storage.write("imagePath", pickedImage.value!.path);
            return Image.file(
              File(pickedImage.value!.path),
              width: 200,
              height: 200,
              fit: BoxFit.cover,
            );
          }
          
        }),
        ElevatedButton(onPressed: (){
          storage.remove("userInfo");
        }, child: Text("点击清除userInfo"))
      ],
    );
  }
}

class CountController extends GetxController {
  var count = 0.obs; // 响应式变量

  void increment() {
    count.value++;
  }
}
